﻿Public Class F16_So_Tiet_Kiem
    Dim DS As New List(Of SoTietKiem)

    Sub HienThi()
        lsvsotietkiem.Items.Clear()
        DS = XL_SoTietKiem.LayDS(Me.Tag)
        For Each s In DS
            Dim li As New ListViewItem(s.NgayLap)
            li.Tag = s
            li.SubItems.Add(s.TaiKhoan)
            li.SubItems.Add(s.SoTien)
            li.SubItems.Add(s.LaiSuat)
            li.SubItems.Add(s.KyHan)
            li.SubItems.Add(s.TuDongGiaHan)
            lsvsotietkiem.Items.Add(li)
        Next
    End Sub

    Private Sub btnlietketknganhang_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnlietketknganhang.Click
        Me.Close()
    End Sub

    Private Sub F16_So_Tiet_Kiem_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        HienThi()
    End Sub

    Private Sub btnthemtk_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnthemtk.Click
        Try
            Dim s As New SoTietKiem
            s.NgayLap = dtp_ngay.Value.Date
            s.NguoiDung = Me.Tag
            s.TaiKhoan = txt_taikhoan.Text
            s.SoTien = Integer.Parse(txt_tiengui.Text)
            s.LaiSuat = Integer.Parse(txt_laisuat.Text)
            s.KyHan = Integer.Parse(txt_kyhan.Text)
            s.ThangDaThu = 0
            s.TuDongGiaHan = ckb_tugiahan.Checked
            XL_SoTietKiem.Them(s)
            HienThi()
        Catch ex As Exception
            MessageBox.Show("Kiểm tra thông tin!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Warning)
            Exit Sub
        End Try
    End Sub

    Private Sub btnxoatk_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnxoatk.Click
        Try
            Dim s As SoTietKiem = lsvsotietkiem.SelectedItems(0).Tag
            XL_SoTietKiem.Xoa(s)
            HienThi()
        Catch ex As Exception
            Exit Sub
        End Try
    End Sub

    Private Sub btnsuatk_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnsuatk.Click
        Try
            Dim s As SoTietKiem = lsvsotietkiem.SelectedItems(0).Tag
            s.NgayLap = dtp_ngay.Value.Date
            s.NguoiDung = Me.Tag
            s.TaiKhoan = txt_taikhoan.Text
            s.SoTien = Integer.Parse(txt_tiengui.Text)
            s.LaiSuat = Integer.Parse(txt_laisuat.Text)
            s.KyHan = Integer.Parse(txt_kyhan.Text)
            s.TuDongGiaHan = ckb_tugiahan.Checked
            XL_SoTietKiem.CapNhat(s)
            HienThi()
        Catch ex As Exception
            MessageBox.Show("Kiểm tra thông tin!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Warning)
            Exit Sub
        End Try
    End Sub

    Private Sub lsvsotietkiem_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lsvsotietkiem.SelectedIndexChanged
        Try
            Dim s As SoTietKiem = lsvsotietkiem.SelectedItems(0).Tag
            dtp_ngay.Value = s.NgayLap
            txt_taikhoan.Text = s.TaiKhoan
            txt_tiengui.Text = s.SoTien.ToString()
            txt_laisuat.Text = s.LaiSuat.ToString()
            txt_kyhan.Text = s.KyHan.ToString()
            ckb_tugiahan.Checked = s.TuDongGiaHan
        Catch ex As Exception
            Exit Sub
        End Try
    End Sub
End Class